API: Add gtk_widget_path_iter_set_object_name()
authorBenjamin Otte <otte@redhat.com>
Tue, 27 Oct 2015 00:26:20 +0000 (01:26 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 27 Oct 2015 00:44:50 +0000 (01:44 +0100)
... and gtk_widget_path_iter_get_object_name(). This allows applications
that still use widget paths to use the new object names to get the
correct styling.

Mutter and webkit-gtk are examples here.

docs/reference/gtk/gtk3-sections.txt
gtk/gtkcssmatcher.c
gtk/gtkwidgetpath.c
gtk/gtkwidgetpath.h

index 360a69c7e868858d5802f0550cc3ff54baa7c7ca..453fdacbaf26bac60314c2d6d0610cb53f904e16 100644 (file)
@@ -5949,6 +5949,7 @@ gtk_widget_path_iter_add_region
 gtk_widget_path_iter_clear_classes
 gtk_widget_path_iter_clear_regions
 gtk_widget_path_iter_get_name
+gtk_widget_path_iter_get_object_name
 gtk_widget_path_iter_get_object_type
 gtk_widget_path_iter_get_siblings
 gtk_widget_path_iter_get_sibling_index
@@ -5964,6 +5965,7 @@ gtk_widget_path_iter_list_regions
 gtk_widget_path_iter_remove_class
 gtk_widget_path_iter_remove_region
 gtk_widget_path_iter_set_name
+gtk_widget_path_iter_set_object_name
 gtk_widget_path_iter_set_object_type
 gtk_widget_path_iter_set_state
 gtk_widget_path_length
index 36b68725933592f7efda7135388ce4f5c8e788b4..71a4cba0a0e591c859ddf9ff26128af332b01853 100644 (file)
@@ -84,9 +84,23 @@ gtk_css_matcher_widget_path_has_name (const GtkCssMatcher     *matcher,
 
   siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
   if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
-    return g_type_is_a (gtk_widget_path_iter_get_object_type (siblings, matcher->path.sibling_index), type);
+    {
+      const char *path_name = gtk_widget_path_iter_get_object_name (siblings, matcher->path.sibling_index);
+
+      if (path_name == NULL)
+        return g_type_is_a (gtk_widget_path_iter_get_object_type (siblings, matcher->path.sibling_index), type);
+
+      return path_name == name;
+    }
   else
-    return g_type_is_a (gtk_widget_path_iter_get_object_type (matcher->path.path, matcher->path.index), type);
+    {
+      const char *path_name = gtk_widget_path_iter_get_object_name (matcher->path.path, matcher->path.index);
+
+      if (path_name == NULL)
+        return g_type_is_a (gtk_widget_path_iter_get_object_type (matcher->path.path, matcher->path.index), type);
+
+      return path_name == name;
+    }
 }
 
 static gboolean
index 0c309d3d8d784a37c77b9d970c29ffbb771bd483..f28ddc990db8275d5faba05f33e272e0f324970b 100644 (file)
@@ -511,6 +511,65 @@ gtk_widget_path_iter_get_sibling_index (const GtkWidgetPath *path,
   return elem->sibling_index;
 }
 
+/**
+ * gtk_widget_path_iter_get_object_name:
+ * @path: a #GtkWidgetPath
+ * @pos: position to get the object name for, -1 for the path head
+ *
+ * Returns the object name that is at position @pos in the widget
+ * hierarchy defined in @path.
+ *
+ * Returns: the name or %NULL
+ *
+ * Since: 3.20
+ **/
+const char *
+gtk_widget_path_iter_get_object_name (const GtkWidgetPath *path,
+                                      gint                 pos)
+{
+  GtkPathElement *elem;
+
+  gtk_internal_return_val_if_fail (path != NULL, NULL);
+  gtk_internal_return_val_if_fail (path->elems->len != 0, NULL);
+
+  if (pos < 0 || pos >= path->elems->len)
+    pos = path->elems->len - 1;
+
+  elem = &g_array_index (path->elems, GtkPathElement, pos);
+  return gtk_css_node_declaration_get_name (elem->decl);
+}
+
+/**
+ * gtk_widget_path_iter_set_object_name:
+ * @path: a #GtkWidgetPath
+ * @pos: position to modify, -1 for the path head
+ * @name: (allow-none): object name to set or %NULL to unset
+ *
+ * Sets the object name for a given position in the widget hierarchy
+ * defined by @path.
+ *
+ * When set, the object name overrides the object type when matching
+ * CSS.
+ *
+ * Since: 3.20
+ **/
+void
+gtk_widget_path_iter_set_object_name (GtkWidgetPath *path,
+                                      gint           pos,
+                                      const char    *name)
+{
+  GtkPathElement *elem;
+
+  gtk_internal_return_if_fail (path != NULL);
+  gtk_internal_return_if_fail (path->elems->len != 0);
+
+  if (pos < 0 || pos >= path->elems->len)
+    pos = path->elems->len - 1;
+
+  elem = &g_array_index (path->elems, GtkPathElement, pos);
+  gtk_css_node_declaration_set_name (&elem->decl, g_intern_string (name));
+}
+
 /**
  * gtk_widget_path_iter_get_object_type:
  * @path: a #GtkWidgetPath
index bd86434012c8c3502b9eb9974261646db2723746..6ef1dbc7bda0339d64403ceb405845f37b7ac975 100644 (file)
@@ -72,6 +72,13 @@ GDK_AVAILABLE_IN_ALL
 void                gtk_widget_path_iter_set_object_type  (GtkWidgetPath       *path,
                                                            gint                 pos,
                                                            GType                type);
+GDK_AVAILABLE_IN_3_20
+const char *        gtk_widget_path_iter_get_object_name  (const GtkWidgetPath *path,
+                                                           gint                 pos);
+GDK_AVAILABLE_IN_3_20
+void                gtk_widget_path_iter_set_object_name  (GtkWidgetPath       *path,
+                                                           gint                 pos,
+                                                           const char          *name);
 GDK_AVAILABLE_IN_ALL
 const GtkWidgetPath *
                     gtk_widget_path_iter_get_siblings     (const GtkWidgetPath *path,